<template>
	<view class="playout">
		<!-- 顶部自定义导航 -->
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<!-- 轮播图 -->
		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay circular duration="500" interval="4000">
				<swiper-item v-for="item in bannerList" :key="item._id">
					<navigator v-if="item.target=='miniProgram'" :url="item.url" target="miniProgram" :app-id="item.appid"> 
						<image :src="item.picurl" mode="aspectFill"></image>
					</navigator>
					<navigator v-else :url="`/pages/classlist/classlist?${item.url}`" class="like">
						<image :src="item.picurl" mode="aspectFill"></image>
					</navigator>
				</swiper-item>
			</swiper>
		</view>
		<!-- 公告轮播 -->
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20" class="uni-icons"></uni-icons>
				<text>公告</text>
			</view>
			<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<swiper-item v-for="item in noticeList" :key="item._id">
						<navigator :url="'/pages/notice/detail?id='+item._id">{{item.title}}</navigator>
					</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="20" color="#333"></uni-icons>
			</view>
		</view>
		<!-- 每日推荐 -->
		<view class="select">
			<common-title>
				<template v-slot:name>
					每日推荐
				</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18" class="uni-icons"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="yy年MM月dd日"></uni-dateformat>
						</view>
					</view>
				</template>
			</common-title>
			<!-- 内容部分 -->
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="item in randomDayList" :key="item._id" @click="goPreview(item._id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 专题精选 -->
		<view class="theme">
			<common-title>
				<template #name>
					专题精选
				</template>
				<template #custom>
					<navigator url="/pages/classify/classify" open-type="switchTab" class="more">More+</navigator>
				</template>
			</common-title>
			<!-- 内容部分 -->
			<view class="content">
				<pic-item v-for="item in classList" :key="item._id" :item="item"></pic-item>
				<pic-item :isMore="true"></pic-item>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { apiGetBanner,apiGetDayRandom,apiGetNotice,apiGetClassList } from '../../api/apis.js';
	
	//轮播图数据
	const bannerList=ref([])
	//每日推荐数据
	const randomDayList=ref([])
	//公告数据
	const noticeList=ref([])
	//分类数据
	const classList=ref([])
	
	//每日推荐跳转到预览页面
	const goPreview=(id)=>{
		uni.setStorageSync("storageClassList",randomDayList.value)
		uni.navigateTo({
			url:"/pages/preview/preview?id="+id
		})
	}
	
	//发送异步同步化的网络请求获取轮播图数据
	async function getBanner(){
		let res=await apiGetBanner()	
		bannerList.value=res.data
	}
	
	//发送异步同步化的网络请求获取每日推荐壁纸
	async function getDayRandom(){
		let res=await apiGetDayRandom()
		randomDayList.value=res.data
	}
	
	//发送异步同步化的网络请求获取新闻公告
	async function getNotice(){
		let res=await apiGetNotice()
		noticeList.value=res.data
		// console.log(res.data)	
	}
	
	//发送异步同步化的网络请求获取分类信息
	async function getClassList(){
		let res=await apiGetClassList({
			select:true
		})
		classList.value=res.data
	}
	
	//分享给好友
	onShareAppMessage((e)=>{
		return {
			title:'贤贤虾壁纸',
			path:'/pages/index/index'
		}
	})
	
	//分享到朋友圈
	onShareTimeline(()=>{
		return {
			title:'贤贤虾壁纸炒鸡好~'
		}
	})
	
	getBanner()
	getDayRandom()
	getNotice()
	getClassList()
</script>

<style scoped lang="scss">
	.playout{
		.banner{
			width: 750rpx;
			padding: 30rpx 0;
			swiper{
				width: 750rpx;
				height: 340rpx;
				&-item{
					width: 100%;
					height: 100%;
					padding: 0 30rpx;
					.like{
						width: 100%;
						height: 100%;
						image{
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}
				}
			}
		}
		.notice{
			display: flex;
			margin: 0 auto;
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			background-color: #f1f1f1;
			border-radius: 40rpx;
			.left{
				display: flex;
				justify-content: center;
				align-items: center;
				width: 140rpx;
				text{
					font-size: 28rpx;
					font-weight: bold;
					color: $brand-theme-color;
				}
				// vue3中控制css的一个穿透
				:deep(){
					.uni-icons{
						color: $brand-theme-color !important;
					}
				}
			}
			.center{
				flex: 1;
				swiper{
					height: 100%;
					&-item{
						height: 100%;
						font-size: 30rpx;
						color: #666;
						//超出不显示
						overflow: hidden;
						//不换行
						white-space: nowrap;
						//省略号代替
						text-overflow: ellipsis;
					}
				}
			}
			.right{
				display: flex;
				justify-content: center;
				align-items: center;
				width: 70rpx;
			}
		}
		.select{
			padding-top: 50rpx;
			.date{
				display: flex;	
				color: $brand-theme-color;
				align-items: center;	
				.text{
					margin-left: 5rpx;
				}
				:deep(){
					.uni-icons{
						color: $brand-theme-color !important;
					}
				}
			}
			.content{
				margin-top: 30rpx;
				margin-left: 30rpx;
				width: 720rpx;
				scroll-view{
					white-space: nowrap;
					.box{
						display: inline-block;
						margin-right: 15rpx;
						width: 200rpx;
						height: 430rpx;
						image{
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
						&:last-child{
							margin-right: 30rpx;	
						}
					}
				}
			}
		}
		.theme{
			padding: 50rpx 0;
			.more{
				font-size: 32rpx;
				color: #888;
			}	
			.content{
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3,1fr);
				margin-top: 30rpx;
				padding: 0 30rpx;
			}
		}
	}
</style>
